package edu.jptest.test;

import java.sql.Connection;
import java.sql.SQLException;

import javax.servlet.GenericServlet;
import javax.servlet.ServletConfig;
import javax.sql.DataSource;

public class GetDatabaseConnection {

	public Connection getConnection() {
	Connection connection = null;
//		try {
//			//System.out.println(getServletContext().getAttribute("dataSource"));
//			//connection = ((DataSource) getServletContext().getAttribute(
//			//		"dataSource")).getConnection();
//			System.out.println(connection);
//			if (connection == null)
//				System.out.println("数据库连接为空");
//			return connection;
//		} catch (SQLException e) {
//			e.printStackTrace();
//		} catch (Exception e) {
//			e.printStackTrace();
//		} finally {
//			if (connection != null)
//				try {
//					connection.close();
//				} catch (SQLException e) {
//					;
//				}
//			connection = null;
//		}
		return connection;
	}
}
